package com.peakproducts;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;

public class PeakTitle extends Field {

	private int backgroundColour = 0xFEDF41;
	//private int highlightColour;
	private int fieldWidth;
	private int fieldHeight;
	private String text;
	private int padding = 6;
	
	public PeakTitle(String text, int bgColor,int width, int height){
		super(Field.FOCUSABLE);
		this.text = text;
		this.backgroundColour = bgColor;
		//highlightColour = bgColor;
		Font defaultFont = Font.getDefault();
		if(height==0)
			fieldHeight = defaultFont.getHeight() + padding;
		else
			fieldHeight = height;
		if(width==0)
			fieldWidth = defaultFont.getAdvance(text) + (padding * 2);
		else{
			fieldWidth = width;
		}
		this.setPadding(0, 0, 0, 0);
	}
	
	public int getPreferredWidth()
	{
		return fieldWidth;
	}

	public int getPreferredHeight()
	{
		return fieldHeight;
	}
	
	protected void layout(int width, int height) {
		setExtent(getPreferredWidth(), getPreferredHeight());
	}

	protected void paint(Graphics graphics) {
		graphics.setColor(backgroundColour);
		//graphics.fillRoundRect(0, 0, fieldWidth, fieldHeight, 0, 0);
		graphics.fillRect(0, 0, fieldWidth, fieldHeight);
		//graphics.setColor(backgroundColour);
		//graphics.drawRoundRect(0, 0, fieldWidth, fieldHeight, 0, 0);
		graphics.setColor(Color.BLACK);
		graphics.drawText(text, 5, 4);
	}
	
}
